import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:trollee/app/components/app_scroll_behavior.dart';
import 'package:trollee/app/core/env/env.dart';
import 'package:trollee/app/core/utils/utils.dart';
import 'package:trollee/app/core/values/values.dart';
import 'package:trollee/app/routes/app_pages.dart';
import 'package:trollee/global.dart';

void main() async {
  await Global.init();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      builder: (_, __) {
        return GetMaterialApp(
          title: DartDefines.appName,
          theme: appThemeData,
          builder: (context, child) {
            return MediaQuery(
              data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
              child: ScrollConfiguration(
                behavior: AppScrollBehavior(),
                child: BotToastInit().call(context, child),
              ),
            );
          },
          navigatorObservers: [
            BotToastNavigatorObserver(),
          ],
          debugShowCheckedModeBanner: false,
          // 日志
          enableLog: !Global.isRelease,
          // 多语言
          locale: AppLocaleUtil.currentLocale,
          fallbackLocale: AppLocaleUtil.fallbackLocale,
          supportedLocales: AppLocaleUtil.supportedLocales,
          localizationsDelegates: const [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          defaultTransition: GetPlatform.isIOS ? Transition.rightToLeft : null,
          // 路由
          getPages: AppPages.routes,
          // 启动页面
          initialRoute: AppPages.initial,
        );
      },
    );
  }
}
